﻿#include "SaveTask.h"
#include <QDir>
#include <QFileInfo>

SaveTask::SaveTask(ImageSaveInfo data)
    :mData(data)
{
    setAutoDelete(true);
}

void SaveTask::run()
{
    QString folder = QFileInfo(mData.path).dir().absolutePath();
    QDir dir(folder);
    if(!dir.exists()){
        dir.mkpath(folder);
    }
    switch(mData.saveType){
    case IST_QIMG:
        mData.img.save(mData.path);
        break;
#ifdef USE_OPENCV
    case IST_CVIMG:
        cv::imwrite(mData.path.toLocal8Bit().data(), mData.cvimg);
        break;
#endif
#ifdef USE_HALCON
    case IST_HIMG:
        HalconCpp::WriteImage(mData.himg, "png", 0, mData.path.toLocal8Bit().data());
        break;
#endif
    }
}
